package indv.cfeng.fianceCampus.serviceCore.controller;


import indv.cfeng.fianceCampus.common.exception.BusinessException;
import indv.cfeng.fianceCampus.common.result.Resp;
import indv.cfeng.fianceCampus.common.result.ResponseEnum;
import indv.cfeng.fianceCampus.serviceCore.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 * 后台管理中字典管理部分
 *
 * @author cfeng
 * @since 2022-10-15
 */
@RestController
@RequestMapping("/admin/dict")
@RequiredArgsConstructor
@Api("数据字段管理")
public class DictController {

    private final DictService dictService;

    @ApiOperation("Excel批量导入数据字典")
    @PostMapping("/import")
    public Resp batchImport(@RequestParam("file") MultipartFile multipartFile) {
        //上传的xmlx文件
        try {
            InputStream inputStream = multipartFile.getInputStream();
            dictService.importData(inputStream);
            return Resp.ok().message("导入成功");
        } catch (Exception e) {
            throw new BusinessException(ResponseEnum.UPLOAD_ERROR,e);
        }

    }
}

